home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Learn C++ (CodeWarrior) / Chap 06.04 - whatAmI / whatAmI.cp < prev    next >
Text File  |  1995-10-20  |  930b  |  70 lines

  1. #include <iostream.h>
  2.  
  3.  
  4. //---------------------------------------  Shape
  5.  
  6. class Shape
  7. {
  8. //            Data members...
  9.         
  10. //            Member functions...
  11.     public:
  12.         virtual void    WhatAmI();
  13. };
  14.  
  15. void    Shape::WhatAmI()
  16. {
  17.     cout << "I don't know what kind of shape I am!\n";
  18. }
  19.  
  20.  
  21. //---------------------------------------  Shape:Rectangle
  22.  
  23. class Rectangle : public Shape
  24. {
  25. //            Data members...
  26.  
  27. //            Member functions...
  28.     public:
  29.         void    WhatAmI();
  30. };
  31.  
  32. void    Rectangle::WhatAmI()
  33. {
  34.     cout << "I'm a rectangle!\n";
  35. }
  36.  
  37.  
  38. //---------------------------------------  Shape:Triangle
  39.  
  40. class Triangle : public Shape
  41. {
  42. //            Data members...
  43.  
  44. //            Member functions...
  45.     public:
  46.         void    WhatAmI();
  47. };
  48.  
  49. void    Triangle::WhatAmI()
  50. {
  51.     cout << "I'm a triangle!\n";
  52. }
  53.  
  54.  
  55. //---------------------------------------  main()
  56.  
  57. int    main()
  58. {
  59.     Shape    *s1, *s2, *s3;
  60.     
  61.     s1 = new Rectangle;
  62.     s2 = new Triangle;
  63.     s3 = new Shape;
  64.     
  65.     s1->WhatAmI();
  66.     s2->WhatAmI();
  67.     s3->WhatAmI();
  68.     
  69.     return 0;
  70. }